package com.yb.project.system.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yb.common.domain.AjaxObject;
import com.yb.common.domain.PageResult;
import com.yb.common.utils.StringUtil;
import com.yb.framework.log.annotation.Log;
import com.yb.framework.log.enums.OperateTypeEnum;
import com.yb.project.base.controller.BaseController;
import com.yb.project.system.domain.SysLogOperate;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/system/log_operate")
@Api(tags = "操作日志管理")
public class SysLogOperateController extends BaseController {
	
	Logger logger = LoggerFactory.getLogger(SysLogOperateController.class.getName());
	
	private static String SYS_LOG_OPERATE = "system/log_operate/log_operate";
	private static String SYS_LOG_OPERATE_ADD = "system/log_operate/log_operate_add";
	private static String SYS_LOG_OPERATE_EDIT = "system/log_operate/log_operate_edit";
	private static String SYS_LOG_OPERATE_INFO = "system/log_operate/log_operate_info";
	
	@GetMapping()
	@PreAuthorize("hasAuthority('system:log_operate')")
	public String main() {
		return SYS_LOG_OPERATE;
	}
	
	@GetMapping("/add_view")
	@PreAuthorize("hasAuthority('system:log_operate:add')")
	public String addView() {
		return SYS_LOG_OPERATE_ADD;
	}
	
	@GetMapping("/edit_view/{id}")
	@PreAuthorize("hasAuthority('system:log_operate:edit')")
	public String editView(@PathVariable("id") Long id, ModelMap model) {
		model.put("sysLogOperate", sysLogOperateService.getById(id));
		return SYS_LOG_OPERATE_EDIT;
	}
	
	@GetMapping("/info/{id}")
	@PreAuthorize("hasAuthority('system:log_operate:info')")
	public String infoView(@PathVariable("id") Long id, ModelMap model) {
		model.put("sysLogOperate", sysLogOperateService.getById(id));
		return SYS_LOG_OPERATE_INFO;
	}
	
	/**
	 * 操作日志列表
	 */
	@PostMapping("/list")
	@PreAuthorize("hasAuthority('system:log_operate:list')")
	@ApiOperation(value="分页查询", notes="分页查询操作日志信息")
	public @ResponseBody PageResult list(SysLogOperate sysLogOperate) {
		startPage();
		return getPageInfo(sysLogOperateService.getPageByEntity(sysLogOperate));
	}
	
	/**
	 * 新增操作日志
	 */
	@PostMapping("/add")
	@PreAuthorize("hasAuthority('system:log_operate:add')")
	@ApiOperation(value="新增操作日志", notes="新增操作日志信息")
	@Log(label = "新增操作日志", operateType = OperateTypeEnum.ADD)
	public @ResponseBody AjaxObject add(SysLogOperate sysLogOperate) {
		return toAjax(sysLogOperateService.insert(sysLogOperate), "新增操作日志");
	}
	
	/**
	 * 编辑操作日志
	 */
	@PostMapping("/edit")
	@PreAuthorize("hasAuthority('system:log_operate:edit')")
	@ApiOperation(value="编辑操作日志", notes="编辑操作日志信息")
	@Log(label = "编辑操作日志", operateType = OperateTypeEnum.EDIT)
	public @ResponseBody AjaxObject edit(SysLogOperate sysLogOperate) {
		return toAjax(sysLogOperateService.update(sysLogOperate), "编辑操作日志");
	}
	
	/**
	 * 删除操作日志
	 */
	@PostMapping("/delete")
	@PreAuthorize("hasAuthority('system:log_operate:delete')")
	@ApiOperation(value="删除操作日志", notes="批量删除操作日志信息")
	@Log(label = "删除操作日志", operateType = OperateTypeEnum.DELETE)
	public @ResponseBody AjaxObject delete(@RequestParam("ids") String ids) {
		return toAjax(sysLogOperateService.deleteListByIds(StringUtil.str2LongArray(ids)), "批量删除操作日志");
	}
}